package com.my.auth.entity;

import lombok.Builder;

import java.util.*;

/**
 * @author zhaodongchao
 * @date 2020/3/21 19:56
 **/
@Builder
public class MyClient  {
    /**
     * 客户端Id
     */
    private String clientId;
    /**
     * 客户端秘钥
     *
     */
    private String clientSecret;

    /**
     * token 有效时间
     */
    private Integer accessTokenValiditySeconds;
    /**
     * 刷新token的有效时间
     */
    private Integer refreshTokenValiditySeconds;

    /**
     * 用来限制客户端访问的权限，在换取的 token 的时候会带上 scope 参数，只有在 scopes 定义内的，才可以正常换取 token。
     * The scope to which the client is limited. If scope is undefined or empty (the default) the client is not limited by scope
     *
     */
    private Set<String> scope = Collections.emptySet();

    /**
     * The resources that this client can access. Can be ignored by callers if empty.
     */
    private Set<String> resourceIds = Collections.emptySet();
    /**
     * 授权类型
     * authorization_code：授权码类型。
     * implicit：隐式授权类型。
     * password：资源所有者（即用户）密码类型。
     * client_credentials：客户端凭据（客户端ID以及Key）类型。
     * refresh_token：通过以上授权获得的刷新令牌来获取新的令牌。
     *
     * Grant types that are authorized for the client to use. Default value is empty.
     */
    private Set<String> authorizedGrantTypes = Collections.emptySet();
    /**
     * 在使用OAuth2协议中的授权码模式（authorization_code）授权时，授权成功后回调客户端的URL
     */
    private Set<String> registeredRedirectUris;

    private Set<String> autoApproveScopes;

    /**
     * Authorities that are granted to the client (regular Spring Security authorities).
     */
    private List<String> authorities = Collections.emptyList();

    /**
     * 额外的信息
     */
    private Map<String, Object> additionalInformation = new LinkedHashMap<String, Object>();

    private String website ;

    public String getClientId() {
        return this.clientId;
    }

    public Set<String> getResourceIds() {
        return this.resourceIds;
    }

    /**
     * Whether a secret is required to authenticate this client.
     */
    public boolean isSecretRequired() {
        return  this.clientSecret != null;
    }

    public String getClientSecret() {
        return this.clientSecret;
    }

    /**
     * Whether this client is limited to a specific scope. If false, the scope of the authentication request will be
     * ignored.
     *
     * @return Whether this client is limited to a specific scope.
     */
    public boolean isScoped() {
        return false;
    }

    public Set<String> getScope() {
        return scope;
    }

    public Set<String> getAuthorizedGrantTypes() {
        return authorizedGrantTypes;
    }

    public Set<String> getRegisteredRedirectUri() {
        return registeredRedirectUris;
    }

    public List<String> getAuthorities() {
        return authorities;
    }

    public Integer getAccessTokenValiditySeconds() {
        return accessTokenValiditySeconds;
    }

    public Integer getRefreshTokenValiditySeconds() {
        return refreshTokenValiditySeconds;
    }

    public boolean isAutoApprove(String scope) {
        return scope != null ;
    }

    public Map<String, Object> getAdditionalInformation() {
        return additionalInformation;
    }
}
